<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title></title>
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link rel="shortcut icon" href="favicon.ico">
	<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
	<link th:href="@{/css/layui.css}" rel="stylesheet" >
	<link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
	<!-- bootstrap-table 表格插件样式 -->
	<link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
	<link th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" rel="stylesheet"/>
	<link th:href="@{/css/animate.css}" rel="stylesheet"/>
	<link th:href="@{/css/style.css}" rel="stylesheet"/>
	<link th:href="@{/css/checkbox.css}" rel="stylesheet"/>
	<link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
	<link th:href="@{/ruoyi/css/ry-ui.min.css}" rel="stylesheet"/>
	<!-- Data Tables -->
	<link th:href="@{/css/plugins/dataTables/dataTables.bootstrap.css}" rel="stylesheet">
	<link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
	<link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-dept-add">
			<input id="treeId" name="parentId" type="hidden"  />
			<div class="form-group">
				<label class="col-sm-3 control-label ">上级部门：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" onclick="selectDeptTree()" id="treeName" readonly="true"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deptName">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">负责人：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="leader">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">联系电话：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="phone">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="email">
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<script th:src="@{/js/jquery.min.js}"></script>
	<script th:src="@{/js/bootstrap.min.js}"></script>
	<!-- jquery-validate 表单验证插件 -->
	<script th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
	<script th:src="@{/ajax/libs/validate/messages_zh.min.js}"></script>
	<script th:src="@{/ajax/libs/validate/jquery.validate.extend.js}"></script>
	<!-- bootstrap-table 表格插件 -->
	<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
	<!-- jquery-export 表格导出插件 -->
	<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js}"></script>
	<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/tableExport.js}"></script>
	<!-- Data Tables -->
	<script th:src="@{/js/plugins/dataTables/jquery.dataTables.js}"></script>
	<script th:src="@{/js/plugins/dataTables/dataTables.bootstrap.js}"></script>
	<script th:src="@{/js/plugins/jeditable/jquery.jeditable.js}"></script>
	<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>
	<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
	<script th:src="@{/ajax/libs/layui/layui.js}"></script>
	<script th:src="@{/ruoyi/js/common.js?v=2.2.0}"></script>
	<script th:src="@{/ruoyi/js/yuyu-ui.min.js?v=2.2.0}"></script>
	<script type="text/javascript">
		$("#form-dept-add").validate({
			rules:{
				deptName:{
					required:true,
					remote: {
		                url: "/checkDeptNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"name" : function() {
		                        return $("input[name='deptName']").val();
		                    }
		                }
		            }
				},
				orderNum:{
					required:true,
					digits:true
				},
			},
			messages: {
		        "name": {
		            remote: "部门已经存在"
		        }
		    },
			submitHandler:function(form){
                var deptId = $("input[name='deptId']").val();
                var parentId = $("input[name='parentId']").val();
                var deptName = $("input[name='deptName']").val();
                var email = $("input[name='email']").val();
                var leader = $("input[name='leader']").val();
                var phone = $("input[name='phone']").val();
                var json={
                    "id":deptId,
                    "parentId" : parentId,
                    "name": deptName,
                    "email":email,
                    "leader":leader,
                    "phone":phone
                };
                $.ajax({
                    url: "/dept/addpost",
                    type: "post",
                    dataType: "json",
                    data: json,
                    success: function(data) {
                        if (data.code==200){
                            layer.msg('添加成功', {icon: 1});
                            setTimeout(function () {
                                parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            },500);
                        }
                    }
                });
            }
		});

		/*部门管理-新增-选择父部门树*/
		function selectDeptTree() {
		    var deptId = $("#treeId").val();
			var url ="/system/dept/selectDeptTree/" + deptId;
			$.modal.open("选择部门", url, '380', '380');
		}
	</script>
</body>
</html>
